home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / miscpas.zip / NEWSPIRO.PAS < prev    next >
Pascal/Delphi Source File  |  1986-02-07  |  10KB  |  554 lines

  1. Program Spiro;
  2.           
  3.             {  Place Cosine and Sine values in two arrays     }
  4.             {  This way you can table lookup instead of       }
  5.             {  calling a trig function.  It's a LOT FASTER!   }
  6.  
  7. const
  8. CosArray: array[1..200] of real =
  9. ( 1.00000,
  10.  0.99951,
  11.  0.99803,
  12.  0.99556,
  13.  0.99211,
  14.  0.98769,
  15.  0.98229,
  16.  0.97592,
  17.  0.96858,
  18.  0.96029,
  19.  0.95106,
  20.  0.94088,
  21.  0.92978,
  22.  0.91775,
  23.  0.90483,
  24.  0.89101,
  25.  0.87631,
  26.  0.86074,
  27.  0.84433,
  28.  0.82708,
  29.  0.80902,
  30.  0.79016,
  31.  0.77051,
  32.  0.75011,
  33.  0.72897,
  34.  0.70711,
  35.  0.68455,
  36.  0.66131,
  37.  0.63742,
  38.  0.61291,
  39.  0.58779,
  40.  0.56208,
  41.  0.53583,
  42.  0.50904,
  43.  0.48175,
  44.  0.45399,
  45.  0.42578,
  46.  0.39715,
  47.  0.36813,
  48.  0.33874,
  49.  0.30902,
  50.  0.27899,
  51.  0.24869,
  52.  0.21814,
  53.  0.18738,
  54.  0.15644,
  55.  0.12533,
  56.  0.09411,
  57.  0.06279,
  58.  0.03141,
  59.  0.00000,
  60. -0.03141,
  61. -0.06279,
  62. -0.09411,
  63. -0.12533,
  64. -0.15643,
  65. -0.18738,
  66. -0.21814,
  67. -0.24869,
  68. -0.27899,
  69. -0.30902,
  70. -0.33874,
  71. -0.36812,
  72. -0.39715,
  73. -0.42578,
  74. -0.45399,
  75. -0.48175,
  76. -0.50904,
  77. -0.53583,
  78. -0.56208,
  79. -0.58778,
  80. -0.61291,
  81. -0.63742,
  82. -0.66131,
  83. -0.68455,
  84. -0.70711,
  85. -0.72897,
  86. -0.75011,
  87. -0.77051,
  88. -0.79015,
  89. -0.80902,
  90. -0.82708,
  91. -0.84433,
  92. -0.86074,
  93. -0.87631,
  94. -0.89101,
  95. -0.90483,
  96. -0.91775,
  97. -0.92978,
  98. -0.94088,
  99. -0.95106,
  100. -0.96029,
  101. -0.96858,
  102. -0.97592,
  103. -0.98229,
  104. -0.98769,
  105. -0.99211,
  106. -0.99556,
  107. -0.99803,
  108. -0.99951,
  109. -1.00000,
  110. -0.99951,
  111. -0.99803,
  112. -0.99556,
  113. -0.99212,
  114. -0.98769,
  115. -0.98229,
  116. -0.97592,
  117. -0.96858,
  118. -0.96029,
  119. -0.95106,
  120. -0.94088,
  121. -0.92978,
  122. -0.91776,
  123. -0.90483,
  124. -0.89101,
  125. -0.87631,
  126. -0.86074,
  127. -0.84433,
  128. -0.82708,
  129. -0.80902,
  130. -0.79016,
  131. -0.77052,
  132. -0.75011,
  133. -0.72897,
  134. -0.70711,
  135. -0.68455,
  136. -0.66131,
  137. -0.63743,
  138. -0.61291,
  139. -0.58779,
  140. -0.56209,
  141. -0.53583,
  142. -0.50904,
  143. -0.48176,
  144. -0.45399,
  145. -0.42578,
  146. -0.39715,
  147. -0.36813,
  148. -0.33874,
  149. -0.30902,
  150. -0.27899,
  151. -0.24869,
  152. -0.21815,
  153. -0.18739,
  154. -0.15644,
  155. -0.12534,
  156. -0.09411,
  157. -0.06279,
  158. -0.03141,
  159.  0.00000,
  160.  0.03141,
  161.  0.06279,
  162.  0.09410,
  163.  0.12533,
  164.  0.15643,
  165.  0.18738,
  166.  0.21814,
  167.  0.24869,
  168.  0.27899,
  169.  0.30901,
  170.  0.33873,
  171.  0.36812,
  172.  0.39714,
  173.  0.42578,
  174.  0.45399,
  175.  0.48175,
  176.  0.50904,
  177.  0.53582,
  178.  0.56208,
  179.  0.58778,
  180.  0.61290,
  181.  0.63742,
  182.  0.66131,
  183.  0.68454,
  184.  0.70710,
  185.  0.72897,
  186.  0.75011,
  187.  0.77051,
  188.  0.79015,
  189.  0.80901,
  190.  0.82708,
  191.  0.84433,
  192.  0.86074,
  193.  0.87630,
  194.  0.89100,
  195.  0.90482,
  196.  0.91775,
  197.  0.92977,
  198.  0.94088,
  199.  0.95105,
  200.  0.96029,
  201.  0.96858,
  202.  0.97592,
  203.  0.98229,
  204.  0.98769,
  205.  0.99211,
  206.  0.99556,
  207.  0.99803,
  208.  0.99951);
  209.  SinArray: array[1..200] of real =
  210. (0.00000,
  211.  0.03141,
  212.  0.06279,
  213.  0.09411,
  214.  0.12533,
  215.  0.15643,
  216.  0.18738,
  217.  0.21814,
  218.  0.24869,
  219.  0.27899,
  220.  0.30902,
  221.  0.33874,
  222.  0.36812,
  223.  0.39715,
  224.  0.42578,
  225.  0.45399,
  226.  0.48175,
  227.  0.50904,
  228.  0.53583,
  229.  0.56208,
  230.  0.58778,
  231.  0.61291,
  232.  0.63742,
  233.  0.66131,
  234.  0.68455,
  235.  0.70711,
  236.  0.72897,
  237.  0.75011,
  238.  0.77051,
  239.  0.79015,
  240.  0.80902,
  241.  0.82708,
  242.  0.84433,
  243.  0.86074,
  244.  0.87631,
  245.  0.89101,
  246.  0.90483,
  247.  0.91775,
  248.  0.92978,
  249.  0.94088,
  250.  0.95106,
  251.  0.96029,
  252.  0.96858,
  253.  0.97592,
  254.  0.98229,
  255.  0.98769,
  256.  0.99211,
  257.  0.99556,
  258.  0.99803,
  259.  0.99951,
  260.  1.00000,
  261.  0.99951,
  262.  0.99803,
  263.  0.99556,
  264.  0.99211,
  265.  0.98769,
  266.  0.98229,
  267.  0.97592,
  268.  0.96858,
  269.  0.96029,
  270.  0.95106,
  271.  0.94088,
  272.  0.92978,
  273.  0.91776,
  274.  0.90483,
  275.  0.89101,
  276.  0.87631,
  277.  0.86074,
  278.  0.84433,
  279.  0.82708,
  280.  0.80902,
  281.  0.79016,
  282.  0.77051,
  283.  0.75011,
  284.  0.72897,
  285.  0.70711,
  286.  0.68455,
  287.  0.66131,
  288.  0.63743,
  289.  0.61291,
  290.  0.58779,
  291.  0.56209,
  292.  0.53583,
  293.  0.50904,
  294.  0.48176,
  295.  0.45399,
  296.  0.42578,
  297.  0.39715,
  298.  0.36813,
  299.  0.33874,
  300.  0.30902,
  301.  0.27899,
  302.  0.24869,
  303.  0.21815,
  304.  0.18738,
  305.  0.15644,
  306.  0.12534,
  307.  0.09411,
  308.  0.06279,
  309.  0.03141,
  310.  0.00000,
  311. -0.03141,
  312. -0.06279,
  313. -0.09411,
  314. -0.12533,
  315. -0.15643,
  316. -0.18738,
  317. -0.21814,
  318. -0.24869,
  319. -0.27899,
  320. -0.30901,
  321. -0.33874,
  322. -0.36812,
  323. -0.39715,
  324. -0.42578,
  325. -0.45399,
  326. -0.48175,
  327. -0.50904,
  328. -0.53582,
  329. -0.56208,
  330. -0.58778,
  331. -0.61290,
  332. -0.63742,
  333. -0.66131,
  334. -0.68454,
  335. -0.70710,
  336. -0.72897,
  337. -0.75011,
  338. -0.77051,
  339. -0.79015,
  340. -0.80901,
  341. -0.82708,
  342. -0.84433,
  343. -0.86074,
  344. -0.87630,
  345. -0.89100,
  346. -0.90483,
  347. -0.91775,
  348. -0.92978,
  349. -0.94088,
  350. -0.95106,
  351. -0.96029,
  352. -0.96858,
  353. -0.97592,
  354. -0.98229,
  355. -0.98769,
  356. -0.99211,
  357. -0.99556,
  358. -0.99803,
  359. -0.99951,
  360. -1.00000,
  361. -0.99951,
  362. -0.99803,
  363. -0.99556,
  364. -0.99212,
  365. -0.98769,
  366. -0.98229,
  367. -0.97592,
  368. -0.96858,
  369. -0.96029,
  370. -0.95106,
  371. -0.94088,
  372. -0.92978,
  373. -0.91776,
  374. -0.90483,
  375. -0.89101,
  376. -0.87631,
  377. -0.86074,
  378. -0.84433,
  379. -0.82708,
  380. -0.80902,
  381. -0.79016,
  382. -0.77052,
  383. -0.75011,
  384. -0.72897,
  385. -0.70711,
  386. -0.68455,
  387. -0.66132,
  388. -0.63743,
  389. -0.61291,
  390. -0.58779,
  391. -0.56209,
  392. -0.53583,
  393. -0.50905,
  394. -0.48176,
  395. -0.45399,
  396. -0.42578,
  397. -0.39715,
  398. -0.36813,
  399. -0.33874,
  400. -0.30902,
  401. -0.27900,
  402. -0.24869,
  403. -0.21815,
  404. -0.18739,
  405. -0.15644,
  406. -0.12534,
  407. -0.09411,
  408. -0.06280,
  409. -0.03142);
  410.  
  411.  
  412.  var
  413.    X1, X2, Y1, Y2, ITh, IK, IH, ColorNum:  integer;
  414.    YWork,CB,A,B,C,Th,H,DeltaAngle: real;
  415.    Fudge1, Fudge2: real;              { Fudge Factors for overflow bug }
  416.    CH: char;
  417.    OK : boolean;
  418.  
  419.  Procedure Putem;
  420.   begin;        
  421.   If X2 = -1000 then                   { skip, if first time        }
  422.      else
  423.         Draw(X1,Y1,X2,Y2,ColorNum);    { draw a line between two points }
  424.         If ITh < 66 then ColorNum := 1              { change colors      }
  425.            else if ITh < 132 then ColorNum := 2     { every now and then }
  426.                 else ColorNum := 3;
  427.         X2 := X1; Y2 := Y1;                         { save new as old    }
  428.   end;
  429.  
  430. Procedure Spiro;
  431. Begin;
  432.  Repeat
  433.    ColorNum := 1;                               { starting color and }
  434.    ITh := 1;                                    { trig array pointer }
  435.    Repeat
  436.         H := CB * Th;                           { part of the equation }
  437.         If H > 6.28318 then
  438.           Repeat
  439.           H := H - 6.28318;                     { get between 0 and 2PI }
  440.           Until H < 6.28318
  441.         Else if H < 0.0 then
  442.           Repeat
  443.           H := H + 6.28318;
  444.           Until H > 0.0;
  445.         IH := Trunc(H/0.0314159)+1;   { convert radians to trig pointer }
  446.         If IH < 1 then IH := 1        { don''t go too low or too high   }
  447.            else If IH > 200 then IH := 200;
  448.  
  449.         { The following Fudge assignments are because a screwy   }
  450.         { integer overflow bug slips in if you let the plot continue }
  451.         { for a long period of time.  Rather than find out why,    }
  452.         { this is just a kludgy pass to get by.                 }
  453.  
  454.         Fudge1 := ((C*CosArray[ITh]) - (B*CosArray[IH])) * 1.1;
  455.         Fudge2 := (C*SinArray[ITh]) - (B*SinArray[IH]);
  456.         If (ABS(Fudge1) > 32767) or (ABS(Fudge2) > 32767) then
  457.            else begin;
  458.                 X1 := Trunc(Fudge1) + 160;     { Get new X and Y  }
  459.                 Y1 := Trunc(Fudge2) + 100;
  460.                 PutEm;                         { Plot Them }
  461.                 end;
  462.         If KeyPressed then begin;
  463.            OK := true;                         {Stop Plotting}
  464.            ITh := 201;
  465.            end;
  466.         Th := Th + DeltaAngle;                 { bump radian angle }
  467.  
  468.            { To get better resolution, change the following statement }
  469.            { to ITH := ITH + 1;  Also, make the DeltaAngle change below }
  470.            { This will give cleaner graphs, but will slow down the  }
  471.            { program by 100%                                        }
  472.         ITh := ITh + 2;                { bump trig pointer }
  473.  
  474.         Until ITh > 200;
  475.      Until OK;
  476. end;
  477.  
  478. begin                                           {first time through}
  479.  X2 := -1000;
  480.  Y2 := -1000;
  481.  ClrScr;
  482.  
  483.         {  See the better resolution statement above.  Change this one }
  484.         { to DeltaAngle := 0.0314159;  Also make the ITH change above. }
  485.         { As mentioned, this will improve resolution at the cost of    }
  486.         { execution speed.                                             }
  487.  DeltaAngle := 0.0314159 * 2;                 { set radian angle increment }
  488.  
  489.  GraphColorMode;
  490.  Palette(2);
  491.  Th := 0;
  492.  B := 13.0;                                   { these A and B parameters }
  493.  A := 87.5;                                   { work well for the title  }
  494.  C := A - B;                                  { screen.                  }
  495.  CB := C / B;
  496.  OK := false;
  497.  GoToXY(19,12);
  498.  Write('TURBO');
  499.  GoToXY(19,13);
  500.  Write('SPIRO');
  501.  GOTOXY(17,14);
  502.  Write('Key=Start');
  503.  Repeat                                       { Plot the title spirograph }
  504.   Spiro;
  505.   If KeyPressed then OK := True;
  506.   Until OK;
  507. Repeat
  508.  ClrScr;
  509.  Writeln;
  510.  Writeln('Written by: Joey Robichaux  (CompuServe: 71336,336) ');
  511.  Writeln('            1036 Brookhollow Drive');
  512.  Writeln('            Baton Rouge, La. 70810');
  513.  Writeln('*Note:');
  514.  Writeln('<"Ctrl" & "C" terminates program,  <anykey> stops graph>');     
  515.  
  516.   { For what its worth, when A is greater than B, you get hypercycloids. }
  517.   { When B is greater than A, you get epicycloids.                       }
  518.  
  519.  Repeat
  520.   GotoXY(1,8);
  521.   BufLen := 5;
  522.   Write('Please enter value between 1 and 100: ','':5);
  523.   GoToXY(39,8);
  524.   Read(B);
  525.   Until (B >= 1) and (B <= 100);
  526.  Repeat
  527.   GotoXY(1,9);
  528.   BufLen := 5;
  529.   Write('Please enter another between 1 and 100: ','':5);
  530.   GoToXY(41,9);
  531.   Read(A);
  532.   Until (A >= 1) and (A <= 100);
  533.  GraphColorMode;
  534.  Palette(2);
  535.  X2 := -1000;                           {First time again}
  536.  Y2 := -1000;
  537.  Th := 0;
  538.  C := A - B;
  539.  CB := C / B;
  540.  OK := false;
  541.  
  542.  Repeat
  543.  Spiro;                                 { start graphing }
  544.  If KeyPressed then OK := true;
  545.  Until OK;
  546. Until true = false;
  547.  end.
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.